﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_System_SalesWorkPart
 * 类型：       控制层

 * 功能说明：   销售工作区显示
 *              
 * 作者：       谈震鸣
 * 创建日期：   2007/12/14
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Main.Bean;
using Shpm.App.Main.Dao;
using Shpm.System;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Commons.Utils;
using Com.CodeProject.Pop3;
using Shpm.App.Input.Dao;
using Shpm.App.Commons.Db.Beans.Inp;
using Shpm.App.Input.Bean;

public partial class App_System_SalesWorkPart : System.Web.UI.UserControl
{
    protected string strStatus(int procId)
    {

        //客户移交
        InpCheckInTaskBean paramBean = new InpCheckInTaskBean();
        paramBean.SaleProcId = procId;
        SaleFinishDao finishDao = new SaleFinishDao();
        IList SaleFinshList = finishDao.FindByCheckInTask(paramBean);
        //资格审核
        SaleProcessDao indefinDao = new SaleProcessDao();
        Shpm.App.Input.Bean.SaleProcessBean indefinBean = new Shpm.App.Input.Bean.SaleProcessBean();
        indefinBean.SaleProcId = procId;
        indefinBean = indefinDao.FindBySaleProcess(indefinBean);
        //体检报告


        //入住资料、购卡阶段
        SaleProcessDao spDao = new SaleProcessDao();
        Shpm.App.Input.Bean.SaleProcessBean personBean = new Shpm.App.Input.Bean.SaleProcessBean();
        personBean.SaleProcId = procId;
        personBean = spDao.FindBySaleProcess(personBean);
        //

        //客户移交
        if (SaleFinshList.Count > 0)
        {
            return "入住移交";
        }
        //资格审核
        else if (indefinBean != null && indefinBean.CancelFlg)
        {
            return "资格审核";
        }
        //体检报告


        //入住资料
        else if (personBean.PersonId != null || personBean.SecondaryPersonId != null || personBean.AccompanyPersonId != null)
        {
            return "入住资料";
        }
        //购卡阶段
        else if (personBean.OrganizationId != null || personBean.RightPersonId != null)
        {
            return "购卡阶段";
        }
        //预销售中
        else
        {
            return "预销售中";
        }

    }
    protected string prepare = string.Empty;
    protected string reside = string.Empty;
    protected string empty = string.Empty;
    protected string employeeId = string.Empty;
    protected string employeeName = string.Empty;
    protected string employeeJob = string.Empty;
    protected string personId = string.Empty;
    protected string userId = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        // 读取销售统计
        SalesMainDao dao = new SalesMainDao();
        // 查询销售过程

        SysUserManager manager = new SysUserManager(Context);
        SysUserBean sysUserBean = manager.getSysUserBean();

        if (sysUserBean != null)
        {
            MstEmployeeBean empBean = sysUserBean.getEmployeeBean();
            MstSysUserBean mstSysUserBean =
                sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
            if (mstSysUserBean != null)
            {
                this.userId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
            }
            if (empBean != null)
            {
                this.employeeId = empBean.EmployeeId;
                this.employeeName = empBean.EmployeeName;
                this.personId = Convert.ToString(empBean.PersonId);

                PersonEmployeeDao personEmployeeDao = new PersonEmployeeDao();
                PersonEmployeeBean personEmployeeBean = new PersonEmployeeBean();
                personEmployeeBean.EmployeeId = empBean.EmployeeId;
                personEmployeeBean = personEmployeeDao.Find(personEmployeeBean);

                this.employeeJob = (personEmployeeBean == null) ? string.Empty : personEmployeeBean.JobName;

                IList dataList = dao.FindSalesByEmployee(empBean);

                Repeater1.DataSource = dataList;
                Repeater1.DataBind();
            }
        }
    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Shpm.App.Main.Bean.SaleProcBean dataBean = (Shpm.App.Main.Bean.SaleProcBean)e.Item.DataItem;

        // 设置销售状态按钮的激活状态

        if (e.Item.ItemIndex >= 0 && dataBean != null)
        {
            int step = 1 + ((dataBean != null && dataBean.CurrentStep == null) ? 0 : dataBean.CurrentStep.Value);

            LinkButton lnkBtn = null;

            if ((lnkBtn = (LinkButton)e.Item.FindControl("Step0")) != null)
            {
                lnkBtn.Enabled = (step >= SalesMainDao.SALE_PROCESS_STEP_0);
                lnkBtn.CommandArgument = Convert.ToString(dataBean.SaleProcId);
            }

            try
            {
                if (int.Parse(dataBean.RelationIntent) < 5)
                {
                    return;
                }
            }
            catch
            {
                return;
            }

            if ((lnkBtn = (LinkButton)e.Item.FindControl("Step1")) != null)
            {
                lnkBtn.Enabled = (step >= SalesMainDao.SALE_PROCESS_STEP_1);
                lnkBtn.CommandArgument = Convert.ToString(dataBean.SaleProcId);
            }

        }
    }

    protected void LinkButton_Command(object sender, CommandEventArgs e)
    {
        // 传递控件参数
        Context.Items["SALE_PROC_ID"] = e.CommandArgument;

        ControllerUtils.Transfer(this.Context, "~/App/Input/SaleCountForm.aspx", true);
    }
}
